import {createRouter, createWebHashHistory} from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      name: 'about',
      component: () => import('../views/AboutView.vue'),
      redirect: '/commodity',
      children: [
        {
          path: '/commodity',
          name: 'commodity',
          component: () => import('../views/manage/MCommodityView.vue')
        },
        {
          path: '/user',
          name: 'user',
          component: () => import('../views/manage/MUserView.vue')
        },
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/LoginView.vue'),
    },
  ],
})
router.beforeEach(async (to) => {
  if (!localStorage.getItem('adminToken') && to.name !== 'login') {
    console.log('先登录')
    return {name: 'login'}
  }
})
export default router
